﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="telephone=no" name="format-detection" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="viewport" content="width=320, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title></title>
    <link href="../Styles/reset.css" rel="stylesheet" />
    <link href="../Styles/header.css" rel="stylesheet" />
    <link href="../Styles/foot.css" rel="stylesheet" />
    <link href="../Styles/Order.css" rel="stylesheet" />
    <script src="../Javascript/jquery-1.6.2.min.js"></script>
</head>
<body>
    <div class="header" id="header">
        <a class="back" href="javascript:history.back();"></a>
        <span class="headline">提交订单</span>
        <a class="search" href="/search?r=search"></a>
    </div>
    <section>
        <div class="order-submit">
            <!-- 订单信息begin -->
            <form>
                <div class="choose add">
                    <h2>收货地址</h2>
                    <a class="content clearfix" onclick="ChooseConsignee()" style="cursor: pointer">
                        <span class="text"><i id="address"></i>
                            <br />
                            <i id="consigneeName"></i><i id="mobile"></i></span>
                        <span class="arrow"></span>
                    </a>
                </div>
                <div class="choose delivery">
                    <h2>配送方式</h2>
                    <a class="content clearfix">
                        <span class="text">快递运输</span>
                    </a>
                </div>
                <div class="choose pay">
                    <h2>支付方式</h2>
                    <a class="content clearfix">
                        <span class="text">货到付款 				
				<input type="hidden" name="payment" value="100" />
                            <input type="hidden" name="pay_name" value="货到付款" />
                        </span>
                        <span class="arrow"></span>
                    </a>
                </div>
                <div class="choose fapiao">
                    <h2>发票信息</h2>
                    <a class="content clearfix">
                        <span class="text">
                            <span class="line1">发票类型：个人</span>
                            <span class="line2">发票内容：酒水</span>
                        </span>
                        <span class="arrow"></span>
                    </a>
                </div>
                <div class="choose list">
                    <h2>商品清单</h2>
                    <ul>
                        <li class="show clearfix">
                            <img id="imgUrl" />
                            <p class="name" id="name"></p>
                            <div class="info">
                                <p class="price" id="price"></p>
                                <p class="num" id="count"></p>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="choose tip">
                    <h2>订单备注</h2>
                    <textarea class="tipInput" tiptext="备注限制在100字以内" value="" name="postscript"></textarea>
                </div>
                <div class="checkout">
                    <div class="count line clearfix">
                        <p class="data data1"><span class="title">商品金额：</span><i></i><span id="goodsPrice">&yen;&nbsp;359.00</span></p>
                    </div>
                    <div class="decrease line clearfix">
                        <p class="data data1"><span class="title">运费：</span><strong>&yen;&nbsp;10</strong></p>
                        <p class="data data1"><span class="title">优惠：</span><strong id="reducePrice"></strong></p>
                    </div>
                    <div class="total line clearfix">
                        <p class="data data1"><span class="title">应付总额：</span><i></i><strong id="TotalPrice"></strong></p>
                    </div>
                </div>
                <input type="button" name="" value="提交订单" class="submit" onclick="SummitOrder()" />
            </form>
        </div>
    </section>

    <script type="text/javascript">
        var CustomerConsigneeInfoID = -1;
        $(document).ready(function () {
            //初始化收货人
            $.ajax({
                url: "../Services/CustomerService.asmx/QueryRecentlyConsignee",
                success: function (data) {
                    if (data.IsSucceed && data.Result != null) {
                        $("#address").html(data.Result.Adress);
                        $("#consigneeName").html(data.Result.ConsigneeUserName);
                        $("#mobile").html(data.Result.ConsigneeMobile);
                        CustomerConsigneeInfoID = data.Result.CustomerConsigneeInfoID;
                    }
                    else {
                        $("#address").html("添加送货地址");
                        $("#consigneeName").html("");
                        $("#mobile").html("");
                        $("#consigneeID").val(-1);
                    }
                }
            });

            //初始化选定商品
            $.ajax({
                url: "../Services/MarketService.asmx/CreateOrder",
                success: function (data) {
                    if (data.IsSucceed) {
                        $("#imgUrl").attr("src", data.Result.ImageUrl);
                        $("#name").html(data.Result.Name);
                        $("#price").html("&yen;&nbsp;" + data.Result.Price);
                        $("#count").html("x" + data.Result.Count);
                        $("#goodsPrice").html("&yen;&nbsp;" + data.Result.Price);
                        $("#reducePrice").html("&yen;&nbsp;" + ((data.Result.MarketPrice - data.Result.Price) * data.Result.Count));
                        $("#TotalPrice").html("&yen;&nbsp;" + (data.Result.Price * data.Result.Count));
                    }
                    else {
                        alert(data.ErrorMessage);
                    }
                }
            });
        });

        function ChooseConsignee() {
            var newUrl = "../Customer/CustomerConsigneeList.html?Url=" + document.location.href;
            document.location.href = newUrl;
        }

        function check_form() {
            var ly = $("textarea[name='postscript']");
            if (ly.val() == '备注限制在100字以内') {
                ly.val('');
            } else if (ly.val().length > 100) {
                alert('订单备注最多不超过100字');
                return false;
            }
            return true;
        }

        function SummitOrder() {
            var consigneeID = parseInt($("#consigneeID").val());
            if (check_form()) {
                var remark = $("textarea[name='postscript']").val();
                $.post(url = '../Services/MarketService.asmx/CommitOrder', data = { consigneeID: CustomerConsigneeInfoID, customerRemarks: remark }, callback = function (data) {
                    if (data.IsSucceed && data.Result) {
                        document.location.href = "../Customer/CustomerCenter.html";
                    } else {
                        alert(data.ErrorMessage);
                    }
                }, 'JSON')
            }
        }

    </script>
</body>
</html>
